home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 February
/
Macworld (1999-02).dmg
/
Shareware World
/
Anti-Virus
/
AntiGax v1.2
/
Source
/
AntigaxCommon.c
< prev
next >
Wrap
Text File
|
1998-10-04
|
3KB
|
120 lines
char RepairApp(short rev);
void WriteString(short fie, uchar *str);
extern FSSpec *lantana;
extern short orrez;
extern Boolean check_only;
char RepairApp(short rev)
{
Handle mdh, menuh;
Str255 stoop;
Str63 nuname;
ulong ule;
long mdlen, mdglobs, l, mdencend, menusz;
short nmdf, i, menid, mdid, j;
uchar obka;
nmdf=Count1Resources('MDEF');
if(!nmdf) return 0;
for(i=0;i<nmdf;i++)
{
mdh=Get1IndResource('MDEF',i+1);
if(!mdh) continue;
if( ((short*)(*mdh))[4] == 'JS' ) break;
}
if(i==nmdf) return 0;
GetResInfo(mdh,&mdid,&ule,stoop);
// WE don't give a Str63 or whatever the virus gives for the name arg in its call!
/* OK, we have a definitely infected app now */
if(check_only) return 1;
/* First find the char it's obfuscated with, and unobfuscate it */
mdlen=GetHandleSize(mdh);
mdglobs=mdlen-0x1E2;
obka=*(mdglobs + 0x2A + *mdh);
mdencend=*(short*)(2+*mdh) + 2;
for(l=0x0A;l<mdencend;l++) (*mdh)[l]^=obka;
/* now get the affected MENU id */
menid=*(short*)(0x0A + *mdh);
/* make sure that menu is still there and full of f's ... well as much as it checks */
menuh=Get1Resource('MENU',menid);
if(!menuh || **menuh!='f')
{
BlockMoveData(lantana->name,nuname,64);
BlockMoveData(".bad",&nuname[nuname[0]+1],4); nuname[0]+=4;
FSpRename(lantana,nuname);
if(orrez)
{
UseResFile(orrez);
ParamText(lantana->name,nil,nil,nil);
Alert(131,nil);
}
return -1;
}
/* now copy the proper data back into it */
menusz=GetHandleSize(menuh);
BlockMoveData(0x0A+*mdh,*menuh,menusz);
ChangedResource(menuh);
/* Now find the lowest-ID menu which was using the virus MDEF as their MDEF and
set them back to 0. There is a small chance this will make a menu using a custom
MDEF which is in another file go back to using the std MDEF (if it installed at
this ID), but these apps would have stuffed up completely when run as infected. */
nmdf=Count1Resources('MENU');
menid=0x7FFF; // works for them
for(i=1;i<=nmdf;i++)
{
menuh=Get1IndResource('MENU',i);
if(!menuh) continue;
if( ((short*)*menuh)[3]!=mdid )
{
HPurge(menuh); // happy now?
continue;
}
GetResInfo(menuh,&j,&ule,stoop);
if(menid>j) menid=j;
}
if(menid<0x7FFF) // just ignore it if we didn't find one I think...
{
menuh=Get1Resource('MENU',menid);
((short*)*menuh)[3]=0;
ChangedResource(menuh);
}
/* And finally, it's time to say goodbye to our favourite resource... */
RemoveResource(mdh);
DisposeHandle(mdh);
UpdateResFile(rev);
/* Good riddance! */
return 1;
}
void WriteString(short fie, uchar *str)
{
long sz;
if(!fie || fie==-1) return;
sz=str[0];
FSWrite(fie,&sz,str+1);
}